package com.yipei.business.controller;

import com.yipei.business.domain.MlTodayNews;
import com.yipei.business.service.IMlTodayNewsService;
import com.yipei.common.annotation.Log;
import com.yipei.common.core.controller.BaseController;
import com.yipei.common.core.domain.AjaxResult;
import com.yipei.common.core.page.TableDataInfo;
import com.yipei.common.enums.BusinessType;
import com.yipei.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 每日解读Controller
 *
 * @author yipei
 * @date 2024-12-23
 */
@RestController
@RequestMapping("/business/mrnews")
@Api(tags = "每日解读", description = "每日解读")
public class MlTodayNewsController extends BaseController {
    @Autowired
    private IMlTodayNewsService mlTodayNewsService;

    /**
     * 查询每日解读列表
     */
    //@PreAuthorize("@ss.hasPermi('business:mrnews:list')")
    @ApiOperation("每日解读获取数据")
    @GetMapping("/list")
    public TableDataInfo list(MlTodayNews mlTodayNews) {
        startPage();
        List<MlTodayNews> list = mlTodayNewsService.selectMlTodayNewsList(mlTodayNews);
        return getDataTable(list);
    }

    /**
     * 导出每日解读列表
     */
    //@PreAuthorize("@ss.hasPermi('business:mrnews:export')")
    @ApiOperation("每日解读导出数据")
    @Log(title = "每日解读", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MlTodayNews mlTodayNews) {
        List<MlTodayNews> list = mlTodayNewsService.selectMlTodayNewsList(mlTodayNews);
        ExcelUtil<MlTodayNews> util = new ExcelUtil<MlTodayNews>(MlTodayNews.class);
        util.exportExcel(response, list, "每日解读数据");
    }

    /**
     * 获取每日解读详细信息
     */
    //@PreAuthorize("@ss.hasPermi('business:mrnews:query')")
    @ApiOperation("每日解读通过ID获取数据")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(mlTodayNewsService.selectMlTodayNewsById(id));
    }

    /**
     * 新增每日解读
     */
    //@PreAuthorize("@ss.hasPermi('business:mrnews:add')")
    @ApiOperation("每日解读新增数据")
    @Log(title = "每日解读", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MlTodayNews mlTodayNews) {
        return toAjax(mlTodayNewsService.insertMlTodayNews(mlTodayNews));
    }

    /**
     * 修改每日解读
     */
    //@PreAuthorize("@ss.hasPermi('business:mrnews:edit')")
    @ApiOperation("每日解读修改数据")
    @Log(title = "每日解读", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MlTodayNews mlTodayNews) {
        return toAjax(mlTodayNewsService.updateMlTodayNews(mlTodayNews));
    }

    /**
     * 删除每日解读
     */
    //@PreAuthorize("@ss.hasPermi('business:mrnews:remove')")
    @ApiOperation("每日解读删除数据")
    @Log(title = "每日解读", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(mlTodayNewsService.deleteMlTodayNewsByIds(ids));
    }
}
